package com.lpx.demo.demo.config.interceptor;

import com.lpx.demo.demo.entity.BaseUserEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class SessionInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        BaseUserEntity user = (BaseUserEntity) request.getSession().getAttribute("user");
        if (user != null) {
            return true;
        }
        request.getRequestDispatcher("/home/login").forward(request,response);
        return false;
    }
}
